package com.cwits.wifi.ui.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.cwits.wifi.R;


/**
 * Created by Administrator on 2016/1/19.
 */
public class SelectDownDialog extends PopupWindow {

    private long tTime = 0;

    private ProgressBar mProgress;
    private OnCancelBtnClickListener mClickListener;

    public interface OnCancelBtnClickListener {
        void onCancleClick();

    }

    public void setCancelListener(OnCancelBtnClickListener ls) {
        mClickListener = ls;
    }

    private View conentView;

    public SelectDownDialog(final Activity context, long Time) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        conentView = inflater.inflate(R.layout.video_undata_dialog, null);
        tTime = Time;
        int h = context.getWindowManager().getDefaultDisplay().getHeight();
        int w = context.getWindowManager().getDefaultDisplay().getWidth();
        // 设置SelectPicPopupWindow的View
        this.setContentView(conentView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();

        // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
        // 设置SelectPicPopupWindow弹出窗体动画效果

        // 设置按钮的点击事件
        TextView button = (TextView) conentView.findViewById(R.id.updata_tv_cancle);
        mProgress = (ProgressBar) conentView.findViewById(R.id.updata_progressbar);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mClickListener.onCancleClick();
               // dismiss();
            }
        });
    }

    public void setProgress(float progress) {
        if(null==mProgress)
            return;
        int a = (int)progress;
        mProgress.setProgress(a);
    }

    /**
     * 显示popupWindow
     *
     * @param parent
     */
    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            // this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);
            this.showAtLocation(parent, Gravity.CENTER, 0, 0);
        } else {
            this.dismiss();
        }
    }


}
